﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dycox.Linq
{
    public struct TimeSpanRange : IRange
    {
        TimeSpan? _upper, _lower;

        public TimeSpanRange(TimeSpan lower)
        {
            _lower = lower;
            _upper = null;
        }

        public TimeSpanRange(TimeSpan lower, TimeSpan upper)
        {
            _lower = lower;
            _upper = upper;
        }

        public TimeSpan LowerBound
        {
            get
            {
                return _lower.GetValueOrDefault(TimeSpan.MinValue);
            }
            set
            {
                _lower = value;
            }
        }

        public TimeSpan UpperBound
        {
            get
            {
                return _upper.GetValueOrDefault(TimeSpan.MaxValue);
            }
            set
            {
                _upper = value;
            }
        }

        public bool IsEmpty
        {
            get { return !_lower.HasValue && !_upper.HasValue; }
        }

        object IRange.LowerBound
        {
            get { return _lower; }
        }

        bool IRange.IsLowerSpecified
        {
            get { return _lower.HasValue; }
        }

        object IRange.UpperBound
        {
            get { return _upper; }
        }

        bool IRange.IsUpperSpecified
        {
            get { return _upper.HasValue; }
        }
    }
}
